<?php

include_once('./includes/phpArmoryCache.class.php');

$armory = new phpArmoryCache();


$player_name =  $_GET['pname'];

$armory_player = $player->getId($player_name);



// $last_updated = $profile->checkForUpdate($armory_player[0]['player_id']);

// $last_updated_time = strtotime(str_replace("-","/",$last_updated));

// $current_time = time();

// $time_difference = ($current_time - $last_updated_time) / 60 / 60;

// if($time_difference > 1)
// {
	
	// $profile->getArmory($player_name, $armory_player[0]['player_id']);

// }

//$player_profile = $profile->get($armory_player[0]['player_id']);

$rp_history = $rp->get($armory_player[0]['player_id']);

/*
foreach ($events as $event_key => $single_event) {
	
	
	$global_signups[$single_event['event_id']]['year']['sub'] = $signup->getYearHistory(0, 0, $single_event['event_id']);
	
	$global_signups[$single_event['event_id']]['year']['main'] = $signup->getYearHistory(0, 1, $single_event['event_id']);

	$global_signups[$single_event['event_id']]['month']['sub'] = $signup->getMonthHistory(0, 0, $single_event['event_id']);
	
	$global_signups[$single_event['event_id']]['month']['main'] = $signup->getMonthHistory(0, 1, $single_event['event_id']);
	
	$global_signups[$single_event['event_id']]['week']['sub'] = $signup->getWeekHistory(0, 0, $single_event['event_id']);
	
	$global_signups[$single_event['event_id']]['week']['main'] = $signup->getWeekHistory(0, 1, $single_event['event_id']);
	
	
	$user_signups[$single_event['event_id']]['year']['sub'] = $signup->getYearHistory($armory_player[0]['user_id'], 0, $single_event['event_id']);
	
	$user_signups[$single_event['event_id']]['year']['main'] = $signup->getYearHistory($armory_player[0]['user_id'], 1, $single_event['event_id']);

	$user_signups[$single_event['event_id']]['month']['sub'] = $signup->getMonthHistory($armory_player[0]['user_id'], 0, $single_event['event_id']);
	
	$user_signups[$single_event['event_id']]['month']['main'] = $signup->getMonthHistory($armory_player[0]['user_id'], 1, $single_event['event_id']);
	
	$user_signups[$single_event['event_id']]['week']['sub'] = $signup->getWeekHistory($armory_player[0]['user_id'], 0, $single_event['event_id']);
	
	$user_signups[$single_event['event_id']]['week']['main'] = $signup->getWeekHistory($armory_player[0]['user_id'], 1, $single_event['event_id']);
	
/*
	$main_history = $signup->getHistory($armory_player[0]['user_id'], 0, $single_event['event_id']);
	
	$events[$event_key]['main_signed_up'] = count($main_history);
	
	foreach ($main_history as $main_key => $main_item) {
		
		$events[$event_key][$main_item['year']][$main_item['month']][$main_item['week']] = $main_item;
		
	}
	
	$sub_history = $signup->getHistory($armory_player[0]['user_id'], 1, $single_event['event_id']);
	
	$events[$event_key]['sub_signed_up'] = count($sub_history);
	
	foreach ($sub_history as $sub_key => $sub_item) {
		
		$events[$event_key][$sub_item['year']][$sub_item['month']][$sub_item['week']] = $sub_item;
		
	}*/

/*echo "<pre>";
print_r($global_signups);
echo "</pre>";
*/


$profile = $armory->characterFetch($player_name, "Tarren+Mill");

if($profile['characterinfo']['errcode'] == 'noCharacter')
{
	echo "No profile found";
}
else
{

	foreach($profile['characterinfo']['charactertab']['items']['item'] as $index => $item)
	{
		$item_xml = $armory->itemFetch($item['id']);

		if (!empty($item_xml))
		{
			$profile['characterinfo']['charactertab']['items']['item'][$index]['detail'] = $item_xml['itemtooltips']['itemtooltip'];
			
			$profile['characterinfo']['charactertab']['items']['item'][$index]['icon'] = $armory->itemIconURL($profile['characterinfo']['charactertab']['items']['item'][$index]['icon']);
			
			$items[$profile['characterinfo']['charactertab']['items']['item'][$index]['slot']] = $profile['characterinfo']['charactertab']['items']['item'][$index];
		}
		//$gem0xml = $armory->itemFetch($profile['characterinfo']['charactertab']['items']['item'][$index]['gem0id']);
		//$gem1xml = $armory->itemFetch($profile['characterinfo']['charactertab']['items']['item'][$index]['gem1id']);
		//$gem2xml = $armory->itemFetch($profile['characterinfo']['charactertab']['items']['item'][$index]['gem2id']);
		
		//if (is_array($gem0xml))
		//	$profile['characterinfo']['charactertab']['items']['item'][$index]['gem0'] = $gem0xml['itemtooltips']['itemtooltip'];
		//if (is_array($gem1xml))
		//	$profile['characterinfo']['charactertab']['items']['item'][$index]['gem1'] = $gem1xml['itemtooltips']['itemtooltip'];
		//if (is_array($gem2xml))
		//	$profile['characterinfo']['charactertab']['items']['item'][$index]['gem2'] = $gem2xml['itemtooltips']['itemtooltip'];

	}




	$smarty->assign('profile', $profile);

	$smarty->assign('items', $items);
}



$smarty->assign('player', $armory_player[0]);



//$smarty->assign('player_profile', $player_profile);

$smarty->assign('rp_bids', $rp_history);

$smarty->display('profile.tpl', $_SESSION['uid']);

$smarty->display('player_statistics.tpl', $_SESSION['uid']);

$smarty->display('player_balance.tpl', $_SESSION['uid']);



?>